package com.example.demo.service.impl;

import com.example.demo.common.SessionUtil;
import com.example.demo.mapper.ArticleMapper;
import com.example.demo.pojo.Article;
import com.example.demo.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-01-07
 * Time: 11:24
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    /**
     * 根据用户名获取文章列表
     * @param username
     * @return
     */
    @Override
    public List<Article> getArticleByUser(String username) {
        return articleMapper.getArticleByUser(username);
    }

    /**
     * 根据用户名获取文章列表
     * @param
     * @return
     */
    @Override
    public List<Article> getArticleList(Integer id) {
        return articleMapper.getArticleList(id);
    }

    /**
     * 查看文章详情
     * @param id
     * @return
     */
    @Override
    public Article getArticleDetails(Integer id) {
        return articleMapper.getArticleDetails(id);
    }

    /**
     * 修改文章
     * @param aid
     * @param uid
     * @param title
     * @param content
     * @return
     */
    @Override
    public int updateArticle(Integer aid, Integer uid, String title, String content) {
        return articleMapper.updateArticle(aid, uid, title, content);
    }

    /**
     * 删除文章
     * @param aid
     * @return
     */
    @Override
    public int deleteArticle(Integer aid) {
        return articleMapper.deleteAricle(aid);
    }

    /**
     * (分页) 获取 主页的文章
     * @param psize
     * @param offset
     * @return
     */
    @Override
    public List<Article> getList(Integer psize, Integer offset) {
        return articleMapper.getList(psize, offset);
    }

    /**
     * 获取 文章的总数
     * @return
     */
    @Override
    public Integer getCount() {
        return articleMapper.getCount();
    }

    /**
     * 发布文章
     * @param uid
     * @param title
     * @param content
     * @return
     */
    @Override
    public int addArticle(Integer uid, String title, String content) {
        return articleMapper.addArticle(uid, title, content);
    }
}
